
** Figure 7: State dependence tests

use "$datadir\ewallet\maindata.dta", clear
	foreach var of varlist logamount  lognumfirms lognewfirms { 
		statsby eff_1=_b[timeid1Xdist500] eff_2=_b[timeid2Xdist500] eff_3=_b[timeid3Xdist500] eff_4=_b[timeid4Xdist500] eff_5=_b[timeid5Xdist500] eff_6=_b[timeid6Xdist500] eff_7=_b[timeid7Xdist500] eff_8 =_b[timeid8Xdist500] eff_9 =_b[timeid9Xdist500] eff_10 =_b[timeid10Xdist500] eff_11=_b[timeid11Xdist500] eff_12 =_b[timeid12Xdist500] eff_13 =_b[timeid13Xdist500] eff_14 =_b[timeid14Xdist500] se_1 =_se[timeid1Xdist500] se_2 =_se[timeid2Xdist500] se_3 = _se[timeid3Xdist500] se_4 =_se[timeid4Xdist500] se_5 =_se[timeid5Xdist500] se_6 =_se[timeid6Xdist500] se_7 =_se[timeid7Xdist500] se_8 =_se[timeid8Xdist500] se_9 =_se[timeid9Xdist500] se_10 =_se[timeid10Xdist500] se_11 =_se[timeid11Xdist500] se_12 =_se[timeid12Xdist500] se_13 =_se[timeid13Xdist500] se_14 =_se[timeid14Xdist500] , saving("$datadir\proptemp`var'_500.dta", replace): reghdfe  `var' timeid*Xdist500 if $filters , a($fe $dist_controls##i.time_id i.state_id##i.time_id) cluster(district_id)
		
	}

qui foreach var in logamount  lognumfirms lognewfirms { 
	use "$datadir\proptemp`var'_500.dta",clear
	
	  gen temp="`var'"
	  local name="`var'"
		if temp=="logamount" {
			local name= "amount transacted"
			local i = 1
			local y_range "-10(5)5"
			local upper 5
			local lower -10
			local numgraph 1
		}
		if temp=="lognumfirms" {
			local name= "# of active firms"
			local i = 3
			local y_range "-4(2)2"
			local upper 2
			local lower -4 
			local numgraph 2
		}
		if temp=="lognewfirms" {
			local name= "# of new adopters"
			local i = 4
			local y_range "-4(2)2"
			local upper 2
			local lower -4
			local numgraph 3
		}
		
	   
	  gen i=1
	  reshape long eff_ se_ , i(i) j(period)
	  drop i
	  rename eff_ eff
	  rename se_ se
	  tset period
	  gen t_10=1.65
	  gen t_5=1.96
	  
	  foreach num in 5 10 {
	  gen low_bound_`num'=eff-(t_`num'*se)
	  gen up_bound_`num'=eff+(t_`num'*se)
	 }
	 replace period = period-6
	
	graph set eps
	graph set window fontface "Garamond"
	g upper = `upper'
	local barcall upper period if inrange(period, 0.5, 3.5), bcolor(gray%20) lcolor(gray%20) base(`lower') lwidth(0)
	twoway (bar `barcall') (rcap up_bound_5 low_bound_5 period, lcolor(gray) lstyle(ci)) (scatter eff period, lcolor(black) mcolor(black) msymbol(circle) msize(medium)) , ///
	legend(off) graphregion(color(white)) ylab(`y_range',nogrid) xlab(-5(1)8)  yline(0, lcolor(black) lwidth(thin)) ///
	xtitle("Time") ytitle("Effect on `name'") xline(0.48 3.52, lcolor(black) lwidth(thin) lpattern(dash)) plotregion(lcolor(black) margin(b=0.25 t=0.25))
	graph export "$outputdir_fig\Figure_7_`numgraph'.pdf", as(pdf) replace
	
	erase "$datadir\proptemp`var'_500.dta"
}
